/**
 * 用户信息store
 */
import { defineStore } from 'pinia'

export const useUserInfoStore = defineStore('user-info', {
  state: () => ({
    userId: '',
    userName: '',
    email: '',
    headImgUrl: '',
    phoneNumber: ''
  }),
  actions: {
    async setUserInfo(userInfo) {
      this.userId = userInfo.id
      this.userName = userInfo.username
      this.email = userInfo.email
      this.headImgUrl = userInfo.headImgUrl
      this.phoneNumber = userInfo.phoneNumber
    },
    async clearUserInfo() {
      this.userId = ''
      this.userName = ''
      this.email = ''
      this.headImgUrl = ''
      this.phoneNumber = ''
    },
    async setUserHeadImgUrl(headImgUrl) {
      this.headImgUrl = headImgUrl
    },
  },
  persist: true,
})
